package org.dei.perla.rockfall.gui.queryforge;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;


import org.dei.perla.sys.device.fpc.dspic.datastructures.MRP;
import org.dei.perla.utils.dataconverter.DataConverter;
import org.dei.perla.utils.dataconverter.annotations.StructInfo;

public class ParserParamFile {
	
	public static void parse(File file, MRP toDeserialize) throws FilterFileParserException, IOException{
		StructInfo structInfo = MRP.class.getAnnotation(StructInfo.class);
		BufferedInputStream  inputStream = new BufferedInputStream(new FileInputStream(file));
		
		long length = file.length();
		
		if(file.length() != structInfo.totalStructSize()){
			throw new FilterFileParserException("File dei parametri corrotto: lunghezza sbagliata. Atteso " + structInfo.totalStructSize() +  " trovato " + file.length());
		}
		
		byte readByte[] = new byte[(int) length];
		inputStream.read(readByte, 0, (int) length);
		DataConverter.fromByteArray(toDeserialize, readByte);
	}

}
